#! /usr/bin/python
#-*- encoding utf-8 -*-
'''
Usage: Http Server using socket
'''

import socket

#Address
HOST = ''
PORT = 8080

#Prepare HTTP response
text_content = '''
HTTP/1.1 200 ok
Content-Type: text/html

<head>
<title>WOW</title>
</head>
<html>
<p>Wow, Python Server</p>
</html>

'''

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((HOST, PORT))
while True:
    sock.listen(3)
    conn, addr = sock.accept()
    request = conn.recv(1024)
    method = request.split(' ')[0]
    src = request.split(' ')[1]
    
    if method == 'GET':
        content = text_content
        conn.sendall(content)
    conn.close()

